#! /bin/bash

echo 'elho_install_user'

#echo nameserver 119.29.29.29 >> /etc/resolv.conf

#yum install -y wget

#wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

firewall-cmd --zone=public --add-port=10050-10060/tcp --permanent
firewall-cmd --reload

setenforce 0
sed -i '/SELINUX=enforcing/s/enforcing/disabled/g' /etc/selinux/config

function addElhoSrv()
{
	#add service
    for svcname in elho-api1 elho-hook elho-si-pc2sync elho-scheduling elho-spider
    do ln -s ${1}/$svcname/bin/$svcname /etc/init.d/$svcname
    done
}

function addElhoDcSrv()
{
	#add service
    for svcname in elho-api
    do ln -s ${1}/$svcname/bin/$svcname /etc/init.d/elho-doctor
    done
}

function addUser()
{
pack_home=/home
#HVA68*k.2A3d
for username in elho elho_doctor h5admin
do
    useradd $username -d ${pack_home}/$username -U -p '$6$VWK336rp$4tDvisjMq5BqIUA3o32yX5spSGbt0S0ellsDJLqENfkh6k5OORgBVEP31vOObG/UK39tCh0Ek6pchiAehyMIF.'
    chown -R $username:$username ${pack_home}/$username
    chmod -R 755 ${pack_home}/$username/release

    case $username in
         elho)
            addElhoSrv ${pack_home}/$username;;
         elho_doctor )
            addElhoDcSrv ${pack_home}/$username;;
    esac

done

sed -i '/^root/a\elho ALL=(ALL)NOPASSWD:ALL\nrop ALL=(ALL)NOPASSWD:ALL\nh5admin ALL=(ALL)NOPASSWD:ALL' /etc/sudoers

for svcname in elho-api1 elho-hook elho-si-pc2sync elho-scheduling elho-spider elho-api-wrapper elho-doctor rop-webapi rop-scheduling rop-backend rop-adaptor niox-h5-webapi
do chkconfig $svcname on
done

}

addUser
